$.extend(validateFunction,{
	FORM_validate2:function(){
		$("#username").Validate(validatePrompt.username,validateFunction.username,true);
		$("#pwd").Validate(validatePrompt.pwd,validateFunction.pwd,true);
		$("#pwd2").Validate(validatePrompt.pwd2,validateFunction.pwd2,true);
		$("#mail").Validate(validatePrompt.mail,validateFunction.mail,true);
		$("#authcode").Validate(validatePrompt.authcode,validateFunction.authcode,true);
//		return validateFunction.FORM_submit(["#username","#pwd","#pwd2","#mail","#authcode"])
        return validateFunction.FORM_submit(["#username","#pwd","#pwd2","#mail","#authcode"])
	}		 
});


setTimeout(function(){$("#mail").get(0).focus();},0);

$("#username").Validate(validatePrompt.username,validateFunction.username);
$("#pwd").bind("keyup",function(){
	validateFunction.pwdstrength();
}).Validate(validatePrompt.pwd,validateFunction.pwd)
$("#pwd2").Validate(validatePrompt.pwd2,validateFunction.pwd2);
$("#mail").Validate(validatePrompt.mail,validateFunction.mail);
$("#authcode").Validate(validatePrompt.authcode,validateFunction.authcode);

$("#viewpwd").bind("click",function(){
	if ($(this).attr("checked")==true){
		validateFunction.showPassword("text");
		$("#o-password").addClass("pwdbg");
	}else{
		validateFunction.showPassword("password");
		$("#o-password").removeClass("pwdbg");
	}
});

$("#registsubmit").click(function() {
var flag = validateFunction.FORM_validate2();
    if (flag) {
        $(this).attr({ "disabled": "disabled" }).attr({ "value": "加载中..." });
        "","#pwd2","#","#"
        var username = $("#username").attr("value");
        var password = $("#pwd").attr("value");
        var email = $("#mail").attr("value");
        
        var data = {"userName": username, "password": password, "email": email};
        
        $.ajax({
        	type: "POST",
            url: "/RemoteSensing/user/signup.action?random=" + Math.random(),
            dataType: "json",
            data: JSON.stringify(data),
            contentType:"application/json",
            success: function(result) {
                if (result.success == "SUCCESS") {
                   /* var obj = eval(result);
                    if (obj.nation) {
                        $("#registsubmit").removeAttr("disabled");
                        $("#registsubmit").attr({ "value": "Submit" });
                        $("#nation_error").html(obj.nation).show().attr({ "class": "error" });
                    }
                    if (obj.info) {
                        $("#registsubmit").removeAttr("disabled");
                        $("#registsubmit").attr({ "value": "Submit" });
                        alert(obj.info);
                        if (obj.info == "The code is incorrect or overdue.") {
                            verc2();
                        }
                    }
                    if (obj.success == true) {
                        var nowtourl = location.search == "" ? "?regsuc=per" : location.search + "&regsuc=per";
						//pageTracker._trackEvent ('Button', 'Regist', 'Normal');
*/                  window.location = "/RemoteSensing/user/success.action?url=" + document.referrer;
                    //}
                }
            }
        });
    }
});

function verc2(){
	$("#Verification").attr("src", "../user/getCaptcha.action?random=" + Math.random());
	$("#Verification").click(function(){
		$(this).attr("src", "../user/getCaptcha.action?random=" + Math.random());
	});
}

$("#authcode").bind('keyup',function(event) {
    if(event.keyCode==13){  
        $("#registsubmit").click();
    }
});

$("#protocol").click(function() {
    if ($("#protocol").attr("checked")!=true) {
        $("#registsubmitframe").attr({ "disabled": "disabled" });
    }
    else {
        $("#registsubmitframe").removeAttr("disabled");

    }
});


